import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessionServlet", value = "/SessionServlet")public class SessionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取
        // 客户端浏览器没有关闭 会话一直存在
        // session 关闭客户端 ，销毁 负责服务器 ，默认存活时间 30分钟
        HttpSession session = request.getSession();
        //存入数据
        //用户信息 User对象；用户名 角色 权限；token-->Redis 去Session化 多端
        session.setAttribute("userName","admin");
        System.out.println("sessionId=="+session.getId());

    }
}
